<html>
    
    <head>
        <script type="text/javascript" src="parseuri.js" />
		<script type='text/javascript' src='common.js' />

        <script>
            chrome.tabs.onUpdated.addListener( function(tabId, changeInfo, tab) {
				if (changeInfo.status == "complete") {
					
					var u = parseUri(tab.url);

					if ( localStorage['stored_host'] ) {
						var stored_host = JSON.parse( localStorage['stored_host'] )
                       	var proxy_url = localStorage['saved_proxy_url'];
						if (!proxy_url) {
							proxy_url = 'proxy.queensu.ca';
							localStorage['saved_proxy_url'] = proxy_url;
						}

						for(var p in stored_host) {
							if ( u['host'].indexOf(p) >= 0 ) {
				                addWebProxy(tab, proxy_url);						
								break;
							}
						}
							
					
					}


                }
			});

			chrome.browserAction.onClicked.addListener(function(tab) {
					
                var proxy_url = localStorage['saved_proxy_url'];
                if (!proxy_url) {
                    proxy_url = 'proxy.queensu.ca';
                    localStorage['saved_proxy_url'] = proxy_url;
				}
                addWebProxy(tab, proxy_url);
					
            });

        </script>
    </head>

</html>

